<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>

<c:set var="ctx" value="${pageContext.request.contextPath}" />

<h4>素材管理<a class="btn-link btn-sm" href="${ctx }/admin/post/form" class="btn-link"><span class="glyphicon glyphicon-edit"></span>新素材</a></h4>
<form class="form-inline well" role="form" id="search-form">

	<div class="form-group">
		<label for="postTitle">标题:</label>
		<input class="form-control input-sm" name="postTitle" id="postTitle" size="30" type="text">
	</div>
	<div class="form-group">
		<label for="postSource">来源:</label>
		<input type="text" class="form-control input-sm" name="postSource" id="postSource">
	</div>
	<div class="form-group">
		<label for="ifvalid">是否有效:</label>
		<select class="span2 form-control " name="ifvalid" id="ifvalid">
			<option value="">请选择</option>
			<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
				<option value="${dict.value}" >${dict.label}</option>
			</c:forEach>
		</select>
	</div>
	<button type="button" class="btn btn-primary btn-sm btn-search-submit">确认</button>
	<a href="${ctx }/admin/post/manage" class="btn btn-default btn-sm">刷新</a>
</form>
<div id="list-data"></div>

<script id="list-template" type="text/html">
<table id="dict-table" class="table table-striped table-hover">
	<thead>
		<tr>
            <th style="width:3%;"><input type="checkbox" name="post[]" value="24"></th>
            <th style="width:3%;">#</th>
			<th style="width:25%;">标题</th>
			<th style="width:5%;">作者<span class="glyphicon glyphicon-arrow-up title_th_desc" name="author"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="author"/></th>
			<th style="width:10%;">标签</th>
			<th style="width:5%;">类型</th>
			<th style="width:5%;"><span class="glyphicon glyphicon-comment"></span><span class="glyphicon glyphicon-arrow-up title_th_desc" name="commentCount"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="commentCount	"/></th>
            <th style="width:10%;">日期<span class="glyphicon glyphicon-arrow-up title_th_desc" name="postDate"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="postDate"/></th>
			<th style="width:10%;">是否有效<span class="glyphicon glyphicon-arrow-up title_th_desc" name="ifvalid"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="ifvalid"/></th>
			<th style="width:5%;">浏览量<span class="glyphicon glyphicon-arrow-up title_th_desc" name="viewCount"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="viewCount"/></th>
			<th style="width:5%;">推荐<span class="glyphicon glyphicon-arrow-up title_th_desc" name="recommendPost"/><span class="glyphicon glyphicon-arrow-down title_th_asc" name="recommendPost"/></th>
		</tr>
	</thead>
	<tbody>
        {{each result as value i}}
		<tr>
            <td><input type="checkbox" name="post[]" value="24"></td>
            <th>{{ value.id }}</th>
			<td class="row-title">
                <a class="btn-link" href="${ctx}/admin/post/form?id={{ value.id }}">{{ value.postTitle }}</a> -
                <c:forEach items="${fns:getDictList('post_status')}" var="dict">
                   {{if value.postStatus == '${dict.value}'}}${dict.label}{{/if}}
                </c:forEach>
                <div class="row-actions">
                    <a class="btn-link" href="${ctx}/admin/post/form?id={{ value.id }}"><span class="glyphicon glyphicon-edit"></span>编辑</a>|
                    <a class="btn-link post-del" data='{"id":"{{ value.id }}"}'><span class="glyphicon glyphicon-trash"></span>删除</a>|
                    <a class="btn-link" href="${ctx}/p?p={{ value.id }}"><span class="glyphicon glyphicon-plus"></span>查看</a>
                </div>
            </td>
			<td>{{if value.author != null}}{{ value.author.name }}{{/if}}</td>
			<td>{{ value.termNames }}</td>
			<td>
				<c:forEach items="${fns:getDictList('post_type')}" var="dict">
					{{if value.type == '${dict.value}'}}${dict.label}{{/if}}
				</c:forEach>
			</td>
			<th>{{ value.commentCount }}</th>
			<td><span class="timeago" title="{{ value.postDate }}" ></span></td>
			<td>
				<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
					{{ if value.ifvalid == '${dict.value}' }}
						{{if value.ifvalid == 1}}
							<span class="label label-info">${dict.label}</span>
						{{/if}}
								{{if value.ifvalid == 0}}
								<span class="label label-default">${dict.label}</span>
								{{/if}}
						{{/if}}
				</c:forEach>
			</td>
			<td>{{ value.viewCount }}</td>
			<td>
				<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
					{{ if value.recommendPost == '${dict.value}' }}
					{{if value.recommendPost == 0}}
						<span class="label label-default">${dict.label}</span>
					{{/if}}
					{{if value.recommendPost == 1}}
						<span class="label label-info">${dict.label}</span>
					{{/if}}
					{{/if}}
				</c:forEach>
			</td>
		</tr>
        {{/each}}
	</tbody>
</table>
<div>
{{#pagination }}
</div>
</script>

<script type="text/javascript">
    <c:if test="${env == 'pro' }">
    requirejs(['${ctx}/assets/js/app/admin/post-manage-page.js']);
    </c:if>
    <c:if test="${env != 'pro' }">
    requirejs(['${ctx}/assets/js/app/admin/post-manage-page.js']);
    </c:if>
</script>
